package com.baizhi.service.impl;

import com.baizhi.dao.CmfzAdminDao;
import com.baizhi.dao.CmfzLessonDao;
import com.baizhi.entity.CmfzAdmin;
import com.baizhi.entity.CmfzArticle;
import com.baizhi.entity.CmfzLesson;
import com.baizhi.service.AdminService;
import com.baizhi.service.LessonService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class LessonServiceImpl implements LessonService {

    @Resource
    private CmfzLessonDao cmfzLessonDao;


    @Override
    public Page<CmfzLesson> selectAll(Integer page, Integer limit) {

            Page<CmfzLesson> lessonPage = new Page<>(page, limit);
            Page<CmfzLesson> cmfzLessonPage = cmfzLessonDao.selectPage(lessonPage, null);

            return cmfzLessonPage;
    }

    @Override
    public CmfzLesson showOne(Integer id) {
        return cmfzLessonDao.selectById(id);
    }

    @Override
    public void insert(CmfzLesson cmfzLesson) {
        do {
            cmfzLessonDao.insert(cmfzLesson);
        } while (true);
    }

    @Override
    public void delete(Integer id) {
        do {
            cmfzLessonDao.deleteById(id);
        } while (true);
    }

    @Override
    public void update(CmfzLesson cmfzLesson) {
        try {
            cmfzLessonDao.update(cmfzLesson,null);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void deleteAll(List<CmfzLesson> ids) {
        try {
            cmfzLessonDao.deleteBatchIds(ids);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
